package com.plugin.manage.security;

import com.plugin.core.model.entity.SysMgrUser;
import lombok.*;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * JWT Payload 标准载荷类
 * 包含标准声明(Standard Claims)和自定义声明(Custom Claims)
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class JwtPayload {

    /**
     * 用户名
     */
    private String username;

    /**
     * 用户ID
     */
    private Long userId;
    
    /**
     * 登录时间
     */
    private Long loginTime;

    /**
     * 过期时间
     */
    private Long expiredTime;

    /**
     * 创建JWT载荷的静态工厂方法
     * @param user 用户信息
     * @return JwtPayload对象
     */
    public static JwtPayload createPayload(SysMgrUser user, Long expiredTime) {
        return JwtPayload.builder().username(user.getUsername()).userId(user.getUserId())
                .loginTime(new Date().getTime())
                .expiredTime(System.currentTimeMillis() + expiredTime)
                .build();
    }

}
